package com.liwenfeng.thread;

import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class FutureTaskTest implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName()+" 执行完");
        return Thread.currentThread().getName()+"====Callable返回数据。。。";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTaskTest callable = new FutureTaskTest();
        FutureTask<String> futureTask1 = new FutureTask<String>(callable);
        FutureTask<String> futureTask2 = new FutureTask<String>(callable);
        FutureTask<String> futureTask3 = new FutureTask<String>(callable);
        new Thread(futureTask1).start();
        new Thread(futureTask2).start();
        new Thread(futureTask3).start();
        System.out.println(futureTask1.get());
        System.out.println(futureTask2.get());
        System.out.println(futureTask3.get());
        ArrayList<Integer> integers = new ArrayList<>();
    }
}
